package com.controller;

import com.listener.MyMessageListener;
import com.service.JMSService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * version 1.0.0
 *
 * @author KKW
 * @date 2017/7/8.
 */
@Controller
public class JMSController {
    @Autowired
    JMSService jmsService;
    @Resource(name = "queuelistener")
    MyMessageListener queueListener;
    @Resource(name = "topiclistener")
    MyMessageListener topicListener;

    @RequestMapping(value = "/jms/jmsQsend/{news}")
    public void messageQSend(@PathVariable("news") String news){
        jmsService.sendQueue(news);
    }

    @RequestMapping(value = "/jms/jmsTsend/{news}")
    public void messageTSend(@PathVariable("news")String news){
        jmsService.sendTopic(news);
    }

    @RequestMapping(value = "/jms/jmsQget")
    @ResponseBody
    public String messageQGet(){
        return queueListener.fetchAMessage();
    }
    @RequestMapping(value = "/jms/jmsTget")
    @ResponseBody
    public String messageTGet(){

        return topicListener.fetchAMessage();
    }
}
